package ru.amse.tsyganov.jumleditor.commands;

import ru.amse.tsyganov.jumleditor.view.lines.Line;

/*package*/ class MoveVerticalLineCommand extends Command {
	
	private final Line line;
	
	private final int oldX1;
	
	private final int oldX2;
	
	private final int newX1;
	
	private final int newX2;

	public MoveVerticalLineCommand(
			Line line, 
			int newX1, 
			int newX2) {
		
		if (line == null) {
			throw new IllegalArgumentException();
		}
		
		this.line = line;
		oldX1 = line.getX1();
		oldX2 = line.getX2();
		this.newX1 = newX1;
		this.newX2 = newX2;
		
		if (oldX2 == newX2 && oldX1 == newX1) {
			throw new IllegalArgumentException();
		}
	}
	
	@Override
	public void execute() {
		line.setX1(newX1);
		line.setX2(newX2);
	}

	@Override
	public void unexecute() {
		line.setX1(oldX1);
		line.setX2(oldX2);
	}

}
